<template>

  <div @click="login">登录</div>

</template>

<script>

  import {adminlogin} from '../api/api'
  import {messageErrorShow,messageSuccessShow} from "../tool/loading";

  import arraytool from '../tool/tool'
  import VueSocketIO from 'vue-socket.io'
  import SocketIO from 'socket.io-client'
  import Vue from 'vue'
  export default {
        name: "Test",
        data(){
          return{
             socket:null,
          }
        },
        mounted() {
          // this.socket = new VueSocketIO({
          //       debug: true,
          //       connection: SocketIO('http://192.168.31.13:9021/agent'),//'http://localhost/agent',//192.168.31.249:9011
          //     });
          // console.log(this.socket);
          // this.socket.emitter.addListener('message',function (resp) {
          //   console.log(resp);
          // },this);
          //
          // this.socket.emitter.addListener('connect',function (data) {
          //   console.log('connect successs');
          //   console.log(data);
          // },this);
        },

      sockets:{
          message:function (data) {
            console.log(data);
            console.log(JSON.parse(data));
            var result = JSON.parse(data);
            if (result.fromUser == "AAC"){
              if (result.msgType == "CC"){
                //chat系统消息
                //是否是建立连接的请求
                this.sessionId = result.sessionId;
                if (result.message.info.url){
                  // this.socketIOClient = SocketIO(result.message.info.url);
                  // this.socketclient = new VueSocketIO({
                  //   debug: true,
                  //   connection:this.socketIOClient,//192.168.31.249:9011
                  // })
                  //
                  // console.log(this.socketIOClient);

                  // this.socketclient.on("message",function (resp) {
                  //   console.log(resp);
                  // }).catch(function (error) {
                  //   console.log(error);
                  // })

                  // this.socketclient.emitter.on("message",function (resp) {
                  //   console.log(resp);
                  // }).catch(function (error) {
                  //   console.log(error);
                  // })

                  // this.socketclient.emitter.addListener('message',function (resp) {
                  //    console.log(resp);
                  // },this);

                }
              }
            }
      },
      connect:function () {
        console.log('connect success')
      },
      //检测socket断开连接
      disconnect:function(){

      },

      //重新连接socket事件
      reconnect:function(){

      },
      chat_message:function (data) {
        console.log(data);
      }
    },

        methods:{
          login(){
            //登录
            this.$router.push('/login');
          }
        },
    }
</script>

<style scoped>

</style>
